/**
 * @Description:
 * @Author bianpengfei
 * @create 2021/6/23 15:05
 */
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { Input } from 'antd'
import PubSub from 'pubsub-js'

class Input1 extends PureComponent {
  constructor(props) {
    super(props)
    this.state = {
      value: ''
    }

    console.log('input-1-constructor', props)
  }

  vModelValue = field => {
    return event => {
      this.setState({
        [field]: event.target.value
      })
      PubSub.publish('emitInputChange', event.target.value)
    }
  }

  render() {
    const { value } = this.state
    return (
      <>
        <h1>组件1 页面</h1>
        <Input placeholder="组件1" value={value} onChange={this.vModelValue('value')} allowClear />
        <button
          onClick={() => {
            const { history } = this.props
            history.push('/input-2?id=100&name=1995')
          }}
        >
          跳转到组件2 页面
        </button>
      </>
    )
  }
}

Input1.propTypes = {}

export default Input1
